<div class="tableform" id="dltype-info-<{$dt_id}>">
<div class="division">
<input type="hidden" name="dt_id" value="<{$dt_id}>">

<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <th><{t}>配送方式名称:<{/t}></th>
    <td><input type="text" name="dt_name" value="<{$dtype.dt_name}>"></td>
    <th>选择默认物流公司</th>
    <td>
      <select name="corp_id">
        <option value="0">请选择物流公司</option>
      <{foreach from=$clist item=corp}>
        <option value='<{$corp.corp_id}>' <{if $corp.corp_id == $corp_id}>selected<{/if}>><{$corp.name}></option>
      <{/foreach}>
      </select>
    </td>
  </tr>
    </table>
   </div>
<div class="division">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <input type="hidden" name="price" value=0>
<!--  <tr>
    <th><{t}>配送费用:<{/t}></th>
    <td><{input type="text" name="price" value=$dtype.price}>
    除了填写固定费用之外，如果您需要按照重量和地区自动灵活计算运费，您可以在此处查看<span class="lnk" title="点击查看配送公式帮助" onclick="new Dialog('index.php?ctl=trading/delivery&act=showRateHelp')"><{t}>配送公式<{/t}></span><{t}>帮助或者使用<{/t}><span class="lnk" title="点击查曼特斯邮资自动计算服务帮助" onclick="new Dialog('index.php?ctl=trading/delivery&act=showMantesHelp')"><{t}>曼特斯邮资自动计算服务<{/t}></span><{t}>帮助。<{/t}></td>
  </tr>-->
  <tr>
    <th><{t}>保价:<{/t}></th>
    <td><input type="radio" name="protect" value="1" onclick="protectPrice(1)" <{if $dtype.protect==1}>checked="checked"<{/if}>><{t}>是<{/t}><input type="radio" name="protect" value="0" onclick="protectPrice(0)"<{if $dtype.protect == 0}>checked="checked"<{/if}>><{t}>否<{/t}></td>
  </tr>
  <tr id="protectrate" <{if $dtype.protect == 0}>style="display:none"<{/if}>>
    <th><{t}>保价百分率:<{/t}></th>
    <td><input type="text" name="protect_rate" value="<{$dtype.protect_rate}>">%</td>
  </tr>
  <tr id="minprotectprice" <{if $dtype.protect == 0}>style="display:none"<{/if}>>
    <th><{t}>最低保价金额:<{/t}></th>
    <td><input type="text" name="minprice" value="<{$dtype.minprice}>"></td>
  </tr>
  <tr>
    <th><{t}>支持货到付款:<{/t}></th>
    <td><input type="radio" name="has_cod" value="1" onclick="hasCod('inline')" <{if $dtype.has_cod == 1}>checked<{/if}>><{t}>是<{/t}><input type="radio" name="has_cod" value="0" onclick="hasCod('none')" <{if $dtype.has_cod == 0}>checked<{/if}>><{t}>否<{/t}></td>
  </tr>
    </table>
    </div>
    <div class="division">
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <th><{t}>支持的配送地区:<{/t}></th>
    <td><{if $area != ''}>
        <!--<h4><{t}>自定义此配送方式所支持的配送地区,点此<{/t}><a id="add_area" href="#" )"><{t}>添加配送地区<{/t}></a>。</h4> //todo: 在这里加上简捷的添加配送地区分方法-->
        <{if $area}>
        <table border="0" cellpadding="0" cellspacing="0" id="area-grid" class="finderInform" >
                <colgroup class="Colsn"></colgroup>
                <colgroup></colgroup>
                <colgroup class="Colamount"></colgroup>
                <colgroup class="Coloption_1b"></colgroup>
        <thead>
         <tr>
          <th><{t}>有效<{/t}></th><!--<input type="checkbox" id="check_all_pay"" >全选-->
          <th><{t}>配送地区<{/t}></th>
          <th><{t}>配送费用<{/t}></th>
          <th><{t}>配送公式<{/t}><label><{t}>（如填写该项，下单时将按该公式来自动计算配送费用，否则就按前面的地区配送费用）<{/t}></label></th>
          <th class="huodaofukuan" style="display:<{if $hasCod}>block<{else}>none<{/if}>"><{t}>货到付款<{/t}></th>
         </tr>
        </thead>
        <tbody id="area-tbody-dom">
        <{foreach item=branch from=$area}>
        <tr>
          <td><input type="checkbox" id="<{$branch.area_id}>" name="area[]" value="<{$branch.area_id}>" onclick="checkCod(this)" <{if $branch.checked}>checked<{/if}> /><input type="hidden" name="areahide[<{$branch.area_id}>]" value="<{$branch.name}>" /></td>
          <td><{$branch.name}></td>
          <td class="Colamount"><input type="text" class="pricevalue" name="money[<{$branch.area_id}>]" size="5" value='<{$branch.price}>' /></td>
          <td class="Expressions" style="text-align:left"><input type="text" id="check_<{$branch.area_id}>" class="priceexp" name="expressions[<{$branch.area_id}>]" size="50" value='<{$branch.expressions}>' /><span class="checkexp sysiconBtnNoIcon" areaid="<{$branch.area_id}>"><{t}>验证<{/t}></span></td>
          <td align="center" class="huodaofukuan" style="display:<{if $hasCod}>block<{else}>none<{/if}>"><input id="iscod_<{$branch.area_id}>" type="checkbox" name="iscod[<{$branch.area_id}>]" value="1" <{if $branch.cod}>checked<{/if}> /></td>
        </tr>
        <{/foreach}>
        </tbody>
        </table>
        <{/if}>
      <{else}>
      您还没有建立配送地区，此配送方式默认所有地区的顾客均能使用。如果您需要不同地区不同配送价格，点此<span class="lnk" onclick="UI.dialog({url:\'ctl=trading/delivery&act=newCropInType\',width:550})"><{t}>添加配送地区<{/t}></span>。
      <{/if}>
    </td>
  </tr>
    </table>
    </div>
	<!-- alone start -->
	<div class="division">
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
		  <tr>
			<th><{t}>最大重量:<{/t}></th>
			<td><input type="text" name="maxWeight" required="true" id="maxWeight" value="<{$maxWeight}>" /></td>
		  </tr>
		</table>
    </div>
	<!-- alone end   -->
    <div class="division">
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <th><{t}>排序:<{/t}></th>
    <td><{input type="unsignedint" name="ordernum" required="true" id="ordernum" value=$dtype.ordernum}></td>
  </tr>
  <tr>
    <th><{t}>详细介绍:<{/t}></th>
    <td><{input type="html" name="detail" value=$dtype.detail}></td>
  </tr>
    </table>
    </div>
<table border="0" align="center" cellpadding="0" cellspacing="0" class="tableAction">
  <tr>
    <td><b class="submitBtn" ><input onclick="javascript: saveDt();" type="button" value="保存"></b></td>
  </tr>
</table>
</div>
<script>
var protectPrice = function(val){
  if(val==1){
    $('protectrate').show();
    $('minprotectprice').show();
  }else{
    $('protectrate').hide();
    $('minprotectprice').hide();
  }
}
var hasCod = function(val){
  $$('.huodaofukuan').setStyle('display',val);
}
var checkCod = function(obj){
  if(obj.checked == false){
    $('iscod_' + obj.value).checked = false;
  }
}

var DialogExp ;
$ES(".checkexp","area-tbody-dom").each(function(item, index, itobj){
  item.addEvent('click',function(e){
    e=new Event(e);
    var ipt=e.target;
    var id = 'check_'+ipt.getAttribute('areaid');
    DialogExp = new Dialog('index.php?ctl=trading/delivery&act=checkExp&area_id='+ipt.getAttribute('areaid')+'&expvalue='+encodeURIComponent($(id).value),{modal:true,title:'验算配送公式'});
  });
});

function saveDt(){
  var nextMark=1;
  $ES(".priceexp","area-tbody-dom").each(function(item, index, itobj){
    var bds = item.value;
    var re = new RegExp("/^[^\]\[\}\{\)\(0-9WwPp\+\-\/\*]+$/");
    if (re.test(bds)){
      alert("公式中含有非法字符");
      item.focus();
      nextMark=0;
      return ;
    }

    var price = 100;
    var weight = 100;
    var str ;
      str = bds.replace(/(\[)/g, "getceil(");
      str = str.replace(/(\])/g, ")");
      str = str.replace(/(\{)/g, "getval(");
      str = str.replace(/(\})/g, ")");
      str = str.replace(/(W)/g, weight);
      str = str.replace(/(w)/g, weight);
      str = str.replace(/(P)/g, price);
      str = str.replace(/(p)/g, price);
      try {
        eval(str);
      }
      catch(e){
        item.focus();
        alert(bds+"公式格式不正确");
        nextMark=0;
        return false;
      }
  });
  if(nextMark == 1){
   $ES('textarea[ishtml=true]',$('dltype-info-<{$dt_id}>')).getValue();
  W.page('index.php?ctl=trading/delivery&act=saveDlType',{data:$('dltype-info-<{$dt_id}>'),method:'post'})
  }
}
function getval(expval){
  if (eval(expval) > 0.000001){
    return 1;
  }else if (eval(expval) >-0.000001&&eval(expval)< 0.000001){
    return 1/2;
  }else{
    return 0;
  }
}
function getceil(expval){
  if (eval(expval) > 0){
    return Math.ceil(eval(expval)-0.000001);
  }else{
    return 0;
  }
}
</script>